import java.util.Map;
import java.util.Set;

import org.dom4j.Element;

import com.alibaba.fastjson.JSONObject;
import com.justep.ui.wx.WXComponentContext;
import com.justep.ui.wx.component.WXComponent;

public class WxRefund extends WXComponent{
	public String getTagName(){
		return "view";
	}
	public JSONObject doExecute(Element bound, Map<String, Object> context, WXComponentContext wxContext) {
		JSONObject props = new JSONObject();	     
		String id = bound.attributeValue("id");
		String outTradeNoExpr = bound.attributeValue("outTradeNoExpr");
		bound.addAttribute("outTradeNoExpr","");
		String outRefundNoExpr = bound.attributeValue("outRefundNoExpr");
		bound.addAttribute("outRefundNoExpr","");
		String totalFeeExpr = bound.attributeValue("totalFeeExpr");
		bound.addAttribute("totalFeeExpr","");
		String refundFeeExpr = bound.attributeValue("refundFeeExpr");
		bound.addAttribute("refundFeeExpr","");

		props.put("outTradeNoExpr", outTradeNoExpr);
		processExprValue(outTradeNoExpr,props,id,"outTradeNoExpr",bound,context,wxContext);
		props.put("outRefundNoExpr", outRefundNoExpr);
		processExprValue(outRefundNoExpr,props,id,"outRefundNoExpr",bound,context,wxContext);
		props.put("totalFeeExpr", totalFeeExpr);
		processExprValue(totalFeeExpr,props,id,"totalFeeExpr",bound,context,wxContext);
		props.put("refundFeeExpr", refundFeeExpr);
		processExprValue(refundFeeExpr,props,id,"refundFeeExpr",bound,context,wxContext);
		
		return props;
	}

	protected void processExprValue(String expr, JSONObject props,String id,String name,Element bound, Map<String, Object> context,WXComponentContext wxContext){
		if(null==expr || "".equals(expr)) return;
		String paramsFn = "$exprBinding_" + id + "_" + name;
		props.put("$executeExprBinding" + "_" + name, paramsFn);
		Set<String> dataIds = getDataIds(bound, context);
		StringBuffer body = new StringBuffer("return " + expr);
		generateFn(paramsFn, body.toString(), wxContext, dataIds);
	}
}